<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>产品报检</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="binding"><i class="layui-icon layui-icon-add-1">  台车绑定</i></button>
	</div>
</script>
<table class="layui-hide" id="bindingList" lay-filter="bindingList"></table>
<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-xs" lay-event="unbind">解绑</a>
	<a class="layui-btn layui-btn-xs" lay-event="rebind">修改绑定</a>
	<a class="layui-btn layui-btn-xs" lay-event="inspect">报检</a>
</script>
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
<script>
layui.use(['table','layer','upload','form'], function(){
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form;
	
	table.render({
	    elem: '#bindingList'
	    ,url:'${pageContext.request.contextPath }/productInspection/selectTrolleyBindingList.do'
	    ,toolbar: '#toolbarDemo'
	    ,title: '绑定列表'
	    ,limits:[10,20,30]
	    ,cols: [[
		  {field:'', title:'序号', sort: true, type:'numbers', width: 60}
		  ,{field:'trolleyNumber', title:'台车编码'}
	      ,{field:'piName', title:'产品名称'}
	      ,{field:'piCode', title:'产品条码'}
	      ,{field:'piStandard', title:'产品规格'}
	      ,{field:'piUnit', title:'计量单位'}
	      ,{field:'piNum', title:'数量'}
	      ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
	    ]]
	    ,page: true
	});
  
	//头工具栏事件
	table.on('toolbar(bindingList)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
		var content = 	'<form class="layui-form layui-card-body" id="addFormId">'+
							'<div class="layui-form-item"><label class="layui-form-label">台车编码111</label><input class="layui-input" lay-verify="trolleyNumber" name="trolleyNumber" type="text" value="" style="width:300px;"></div>'+
							'<div class="layui-form-item"><label class="layui-form-label">产品名称</label><input class="layui-input" lay-verify="piName" name="piName" type="text" value="" style="width:300px;"></div>'+
							'<div class="layui-form-item"><label class="layui-form-label">产品条码</label><input class="layui-input" lay-verify="piCode" name="piCode" type="text" value="" style="width:300px;"></div>'+
							'<div class="layui-form-item"><label class="layui-form-label">产品规格</label><input class="layui-input" lay-verify="piStandard" name="piStandard" type="text" value="" style="width:300px;"></div>'+
							'<div class="layui-form-item"><label class="layui-form-label">计量单位</label><input class="layui-input" lay-verify="piUnit" name="piUnit" type="text" value="" style="width:300px;"></div>'+
							'<div class="layui-form-item"><label class="layui-form-label">数量</label><input class="layui-input" lay-verify="piNum" name="piNum" type="number" value="" style="width:300px;"></div>'+
							'<input class="layui-hide" lay-verify="tStatus" name="tStatus" value="0">'+
						  		'<div class="layui-form-item"><div class="layui-input-block">'+
									'<button id="subBtn1" class="layui-btn layui-btn-blue" lay-submit lay-filter="addform">绑定</button><button type="reset" id="addReset" class="layui-btn layui-btn-primary" style="margin-left:140px">重置</button>'+
								'</div></div>'+
							'</form>';
	    switch(obj.event){
	    	case 'binding':
	    		layer.open({
					  type: 1 		//Page层类型
					  ,area: ['500px', '500px'] //宽  高
					  ,title: '台车绑定'
					  ,shade: 0.1 	//遮罩透明度
					  ,maxmin: true //允许全屏最小化
					  ,anim: 1 		//0-6的动画形式，-1不开启
					  ,content: content
					  ,success:function(layero, index){
						  form.render();
					  }
					});
	      	break;
	    };
	});
  
	//监听行工具事件
	table.on('tool(bindingList)', function(obj){
		var data = obj.data;
		console.log(obj)
		if(obj.event === 'unbind'){
		  layer.confirm('确定解绑吗？', function(index){
		    var tId = obj.data.tId;
		    $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/productInspection/deleteTrolleyBinding.do',
		    	data:{"tId":tId},
		    	success:function(data){
		    		if(data>0){
		    			toastr.success("解绑成功！");
		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
		    		}else{
		    			toastr.warning("解绑失败！");
		    		}
		    	}
		    		
		    })
		    layer.close(index);
		  });
		} else if(obj.event === 'rebind'){
			var tId = obj.data.tId;
			var content1 = '<form class="layui-form layui-card-body" id="editFormId">'+
								'<input class="layui-hide" lay-verify="tId" name="tId" type="text" value="'+tId+'">'+
								'<div class="layui-form-item"><label class="layui-form-label">台车编码</label><input class="layui-input" lay-verify="trolleyNumber" name="trolleyNumber" type="text" value="'+obj.data.trolleyNumber+'" style="width:300px;"></div>'+
								'<div class="layui-form-item"><label class="layui-form-label">产品名称</label><input class="layui-input" lay-verify="piName" name="piName" type="text" value="'+obj.data.piName+'" style="width:300px;"></div>'+
								'<div class="layui-form-item"><label class="layui-form-label">产品条码</label><input class="layui-input" lay-verify="piCode" name="piCode" type="text" value="'+obj.data.piCode+'" style="width:300px;"></div>'+
								'<div class="layui-form-item"><label class="layui-form-label">产品规格</label><input class="layui-input" lay-verify="piStandard" name="piStandard" type="text" value="'+obj.data.piStandard+'" style="width:300px;"></div>'+
								'<div class="layui-form-item"><label class="layui-form-label">计量单位</label><input class="layui-input" lay-verify="piUnit" name="piUnit" type="text" value="'+obj.data.piUnit+'" style="width:300px;"></div>'+
								'<div class="layui-form-item"><label class="layui-form-label">数量</label><input class="layui-input" lay-verify="piNum" name="piNum" type="number" value="'+obj.data.piNum+'" style="width:300px;"></div>'+
									'<div class="layui-form-item"><div class="layui-input-block">'+
										'<button class="layui-btn layui-btn-blue" lay-submit lay-filter="editform">立即提交</button><button type="editReset" id="reset" class="layui-btn layui-btn-primary" style="margin-left:140px">重置</button>'+
									'</div></div>'+
							'</form>';
			layer.open({
				  type: 1 		//Page层类型
				  ,area: ['500px', '450px'] //宽  高
				  ,title: '修改绑定'
				  ,shade: 0.1 	//遮罩透明度
				  ,maxmin: true //允许全屏最小化
				  ,anim: 1 		//0-6的动画形式，-1不开启
				  ,content: content1
				});
		}else if(obj.event === 'inspect'){
			var tId = obj.data.tId;
			var piNumber = "PI"+(new Date()).getTime(); 
			var trolleyNumber = obj.data.trolleyNumber; 
			$.ajax({
				type : "post"
				,url : '${pageContext.request.contextPath}/productInspection/productInspection.do'
				,data : {tId:tId,piNumber:piNumber,trolleyNumber:trolleyNumber}
				,cache : false
				,async:false
				,success:function(res){
					if(res>0){
						toastr.success("报检成功！");
		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							// 父页面刷新
							window.location.reload();  
						},2000);
		    		}else{
		    			toastr.warning("报检失败！");
		    		}
				}
			})
		}
	});
    /**
     * 通用表单提交(AJAX方式)（新增）
     */
    form.on('submit(addform)', function (data) {
    	$("#subBtn1").attr("disabled",true);
    	$.ajax({
			type : "post",
			url : '${pageContext.request.contextPath}/productInspection/addTrolleyBinding.do',
			data : $("#addFormId").serialize(),
			cache : false,
			async:false
			}).done(
				function(res) {
					if (res == 1) {
						toastr.success('绑定成功！');
					}
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
						//关闭模态框
						// 父页面刷新
						window.location.reload();  
					},2000);
				}
			).fail(
				function(res) {
					toastr.error('绑定失败！');
				}
			)
			return false;
    });
    /**
     * 通用表单提交(AJAX方式)(修改)
     */
    form.on('submit(editform)', function (data) {
    	$.ajax({
			url : '${pageContext.request.contextPath}/productInspection/editTrolleyBinding.do',
			data : $("#editFormId").serialize(),
			cache : false,
			async:false
			/* 
				success: function (data) {},
				error: function (XMLHttpRequest, textStatus, errorThrown) {},
				beforeSend: function () {},
				complete: function () {} 
			 */
			}).done(
				function(res) {
					if (res == 1) {
						toastr.success('修改成功！');
					}
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
						//关闭模态框
						// 父页面刷新
						window.location.reload();  
					},2000);
				}
			).fail(
				function(res) {
					toastr.error('修改失败！');
				}
			)
			return false;
    });
});

toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>
</body>
</html>